const app = getApp()
import util from '../../utils/util'
import {
  ScoreBankType,
  BlackList,
  RedList,
  NewRedList,
  GetLevelHomeList
} from '../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 10,
    topMenus: [], //积分银行顶部菜单数据
    redlist: [], //积德积星列表
    newRedList: [], // 红榜
    blacklist: [], //黑榜列表
    lists: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    starFmailySort: [],
    baseImgUrl:app.globalData.baseImgUrl
  },

  BankToDetail: function(e) {
    let id = e.currentTarget.dataset['index'];
    console.log('点击了积分银行详情', id);
    wx.navigateTo({
      url: '/pages/integralBank/integralDetail/integralDetail?id=' + id + '&title=' + e.currentTarget.dataset['title']
    });
  },
  /**
   * 跳转到详情页面
   */
  toStarFamily: function() {
    wx.navigateTo({
      url: '/pages/integralBank/StarFamilyDetail/StarFamilyDetail'
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log('积分银行：', options.type);
    let that = this;
    let y = new Date().getFullYear(); //当前系统年份

    util.apiRequest(GetLevelHomeList, {
      year: y,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('星级家庭列表数据；', r.data.data);
      that.setData({
        starFmailySort: r.data.data
      })

    });

    util.apiRequest(ScoreBankType, {
      type: 2,
      pid: 0,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('积分银行顶部菜单：', r.data.data);
      that.setData({
        topMenus: r.data.data,
      });
    });

    // BlackList,RedList
    // util.apiRequest(RedList, {
    //   limit: 10,
    //   page:1
    // }, null).then(r => {
    //   that.setData({
    //     redlist: r.data.data.data,
    //   });
    // }); 

    util.apiRequest(BlackList, {
        page:1,
        limit:100,
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('黑榜内容：', r.data.data.data);
      that.setData({
        blacklist: r.data.data.data,
      });
    }); //黑榜

    this.getNewRed()
  },

  getNewRed() {
    let that = this;
    util.apiRequest(NewRedList, {
      vollege_id: app.globalData.vollege_id
    }, null).then(r => {
      console.log('红榜：', r)
      that.setData({
        newRedList: r.data.data
      })
    })
  },


  /**
   * 跳转到名单详情页面
   */
  toListDetail: function(e) {
    console.log('跳转到名单详情页面！', e.currentTarget.dataset['id']);
    wx.navigateTo({
      url: '/pages/integralBank/ListDetail/ListDetail?id=' + e.currentTarget.dataset['id']
    });
  },

  /**
   * 跳转到积分详情页面
   */
  toScoreDetail: function(e) {
    console.log('跳转到积分详情页面！', e.currentTarget.dataset['id']);
    console.log('跳转到积分详情页面code！', e.currentTarget.dataset['code']);
    wx.navigateTo({
      url: '/pages/integralBank/StarFamilyDetailPage/StarFamilyDetailPage?id=' + e.currentTarget.dataset['id'] + '&code=' + e.currentTarget.dataset['code']
    });
  },


  toScoreStore(){
    let that = this;
    console.log('跳转前往积分商城！');
    wx.navigateTo({
      url:'/pages/store/store'
    });
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})